from pyecharts import options as opts
from pyecharts.charts import Liquid

# 创建一个Liquid实例
liquid = Liquid()

# 设置水球图的值
liquid.add(
    "完成率",
    [0.65],  # 百分比
    label_opts=opts.LabelOpts(
        font_size=50,  # 字体大小
        position="inside",
        color="#FFFFFF"
    ),
    color=["#288EFF"],  # 水球的颜色
)

# 设置水球图的全局选项
liquid.set_global_opts(
    title_opts=opts.TitleOpts(
        title="2022年上半年目标完成率",  # 主标题
        subtitle="截至6月30日销售目标总体完成率达到65%",  # 副标题
        title_textstyle_opts=opts.TextStyleOpts(color="#FFFFFF", font_size=25),  # 标题样式
        subtitle_textstyle_opts=opts.TextStyleOpts(color="#FFFFFF", font_size=15),  # 副标题样式
        pos_left="center",
    ),
    # 背景颜色
    graphic_opts=[
        opts.GraphicRect(
            graphic_item=opts.GraphicItem(
                left="center",
                top="center",
                z=-10,  # 设置z-index，使背景在最底层
            ),
            graphic_shape_opts=opts.GraphicShapeOpts(width=800, height=500),
            graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="#1A1E43")
        )
    ]
)

# 渲染图表
liquid.render("liquid_chart.html")
